//
//  ContentModel.m
//  budejiePersonalPage
//
//  Created by 李叶夫 on 16/8/29.
//  Copyright © 2016年 李叶夫. All rights reserved.
//

#import "ContentModel.h"
#import "ContentNetWorkTool.h"
#import <Foundation/Foundation.h>


@implementation ContentModel

+ (instancetype)contentModelWithDic:(NSDictionary *)dic
{
    ContentModel *model = [ContentModel new];
    
    [model setValuesForKeysWithDictionary:dic];
    
    return model;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    
}


+ (void)loadDataWithUrlstr:(NSString *)urlstr successBlock:(void (^)(NSArray *))successBlock failBlock:(void (^)(NSError *))failBlock
{
    [[ContentNetWorkTool sharedContentNetWorkTool] GET:urlstr parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task,   NSDictionary *responseObject) {
        
//        NSLog(@"responseObject=====%@",responseObject);
        
        NSArray *listArr = responseObject[@"list"];
        
        NSMutableArray *marr = [NSMutableArray arrayWithCapacity:listArr.count];
        
        [listArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            
            ContentModel *model = [ContentModel contentModelWithDic:obj];
            
            [marr addObject:model];
        }];
        
        if (successBlock) {
            successBlock(marr.copy);
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failBlock) {
            failBlock(error);
        }
        
    }];
}


@end
